package com.smile.service.impl;

import com.smile.model.dto.request.*;
import com.smile.service.PayloadService;
import com.smile.service.task.FlyServicesExecutor;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.stereotype.Service;

@Service
public class PayloadServiceImpl implements PayloadService {
    @Override
    public void payloadAuthorityGrab(PayloadAuthorityGrabRequestDTO payloadAuthorityGrabRequestDTO) throws MqttException {
        FlyServicesExecutor.create()
                .payloadAuthorityGrab(payloadAuthorityGrabRequestDTO.getPayloadIndex())
                .gateway(payloadAuthorityGrabRequestDTO.getGateway())
                .execute();
    }

    @Override
    public void cameraPhotoTake(CameraPhotoTakeRequestDTO cameraPhotoTakeRequestDTO) throws MqttException {
        FlyServicesExecutor.create()
                .cameraPhotoTake(cameraPhotoTakeRequestDTO.getPayloadIndex())
                .gateway(cameraPhotoTakeRequestDTO.getGateway())
                .execute();
    }

    @Override
    public void cameraPhotoStop(CameraPhotoStopRequestDTO cameraPhotoStopRequestDTO) throws MqttException {
        FlyServicesExecutor.create()
                .cameraPhotoStop(cameraPhotoStopRequestDTO.getPayloadIndex())
                .gateway(cameraPhotoStopRequestDTO.getGateway())
                .execute();
    }

    @Override
    public void cameraRecordingStart(CameraRecordStartRequestDTO cameraRecordStartRequestDTO) throws MqttException {
        FlyServicesExecutor.create()
                .cameraRecordStart(cameraRecordStartRequestDTO.getPayloadIndex())
                .gateway(cameraRecordStartRequestDTO.getGateway())
                .execute();
    }

    @Override
    public void cameraRecordingStop(CameraRecordStopRequestDTO cameraRecordStopRequestDTO) throws MqttException {
        FlyServicesExecutor.create()
                .cameraRecordStop(cameraRecordStopRequestDTO.getPayloadIndex())
                .gateway(cameraRecordStopRequestDTO.getGateway())
                .execute();
    }

    @Override
    public void cameraModeSwitch(CameraModeSwitchRequestDTO cameraModeSwitchRequestDTO) throws MqttException {
        FlyServicesExecutor.create()
                .cameraModeSwitch(cameraModeSwitchRequestDTO.getPayloadIndex(), cameraModeSwitchRequestDTO.getCameraMode())
                .gateway(cameraModeSwitchRequestDTO.getGateway())
                .execute();
    }

    @Override
    public void videoStorageSet(VideoStorageSetRequestDTO videoStorageSetRequestDTO) throws MqttException {
        FlyServicesExecutor.create()
                .videoStorageSet(videoStorageSetRequestDTO.getVideoStorageSettings(),
                        videoStorageSetRequestDTO.getPayloadIndex())
                .gateway(videoStorageSetRequestDTO.getGateway())
                .execute();
    }

    @Override
    public void photoStorageSet(PhotoStorageSetRequestDTO photoStorageSetRequestDTO) throws MqttException {
        FlyServicesExecutor.create()
                .photoStorageSet(photoStorageSetRequestDTO.getPhotoStorageSettings(), photoStorageSetRequestDTO.getPayloadIndex())
                .gateway(photoStorageSetRequestDTO.getGateway())
                .execute();
    }

    @Override
    public void gimbalReset(GimbalResetRequestDTO gimbalResetRequestDTO) throws MqttException {
        FlyServicesExecutor.create()
                .gimbalReset(gimbalResetRequestDTO.getResetMode(), gimbalResetRequestDTO.getPayloadIndex())
                .gateway(gimbalResetRequestDTO.getGateway())
                .execute();
    }

    @Override
    public void cameraFocalLengthSet(CameraFocalLengthSetRequestDTO cameraFocalLengthSetRequestDTO) throws MqttException {
        FlyServicesExecutor.create()
                .CameraFocalLengthSet(cameraFocalLengthSetRequestDTO.getCameraType(), cameraFocalLengthSetRequestDTO.getZoomFactor(), cameraFocalLengthSetRequestDTO.getPayloadIndex())
                .gateway(cameraFocalLengthSetRequestDTO.getGateway())
                .execute();
    }


    @Override
    public void cameraScreenDrag(CameraScreenDragRequestDTO cameraFocalLengthSetRequestDTO) throws MqttException {
        FlyServicesExecutor.create()
                .CameraScreenDrag(cameraFocalLengthSetRequestDTO.getLocked(), cameraFocalLengthSetRequestDTO.getPitchSpeed(),cameraFocalLengthSetRequestDTO.getYawSpeed(), cameraFocalLengthSetRequestDTO.getPayloadIndex())
                .gateway(cameraFocalLengthSetRequestDTO.getGateway())
                .execute();
    }

    @Override
    public void cameraFrameZoom(CameraFrameZoomRequestDTO cameraFrameZoomRequestDTO) throws MqttException {
        FlyServicesExecutor.create()
                .cameraFrameZoom(cameraFrameZoomRequestDTO.getLocked(), cameraFrameZoomRequestDTO.getX(),cameraFrameZoomRequestDTO.getY(),cameraFrameZoomRequestDTO.getWidth(),cameraFrameZoomRequestDTO.getHeight(),cameraFrameZoomRequestDTO.getCameraType(), cameraFrameZoomRequestDTO.getPayloadIndex())
                .gateway(cameraFrameZoomRequestDTO.getGateway())
                .execute();
    }
}
